<%@ page contentType="text/html;charset=UTF-8"%>

<style type="text/css">
	#jscstcc {
		width: 410px;
	}
	
	.yqjsqta {
		padding: 22px 30px 0;
	}
	.tccgb {
    position: absolute;
    top: 20px;
    right: 15px;
    overflow: hidden;
    width: 16px;
    cursor: pointer;
    font-size:20px;
	}
	#jgsztcc,#txmestcc{ overflow:hidden; width:370px; height:258px; border:1px solid #959595; background-color:#fff; margin-left:-186px!important; margin-top:-129px!important; position:fixed!important; _position:absolute; left:50%; top:50%; z-index:1993; -moz-border-radius:5px; border-radius:5px; -webkit-box-shadow: #999 0px 0px 8px; -moz-box-shadow: #999 0px 0px 8px; box-shadow: #999 0px 0px 8px; }
    #jgsztcc{ overflow:hidden; width:528px; height:374px; border:1px solid #aaa; background-color:#fff; margin-left:-265px!important; margin-top:-188px!important; position:fixed!important; _position:absolute; left:50%; top:50%; z-index:1994; }
    .tcctop{ height:39px; line-height:39px; padding:14px 0  0 14px; margin:0 10px; color:#333; font-size:14px; font-weight:bold; border-bottom:4px solid #e7e7e7; }

	#zzc{ background-color:#000; width:100%; height:100%; filter:alpha(opacity=30); opacity:0.3; position:fixed!important; _position:absolute; left:0; top:0; z-index:1992; }
</style>

<style type="text/css">
	@import	url(${ctx}/js/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css);
</style>

<script type="text/javascript" src="${ctx}/js/plupload/plupload.full.js"></script>
<script type="text/javascript" src="${ctx}/js/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/js/plupload/i18n/cn.js"></script>

<script type="text/javascript">
	var fileids = "";
	var fileList = [];
	var filePath = "";
	var noUploadFiles = [];
	var uploade = null;
	
	$(function() {
		$(".tccgb").click(function() {
			  fileUploadFinish();
		});
	});

	function fileUploadFinish() {
	 	if (uploade != null && uploade.state == 1 && uploade.files.length > 0) {
	 		layer.msg("您有文件未上传！");
	 		return;
	 	}
	 	
	    $("#upload").hide();
	}
	
	function upload(type) {
		init(type);
		$("#upload").show();
		init();
	}
	
	var files = [];
	var errors = [];
	
	function init(type) {
		//$(function() {
			$("#uploader").pluploadQueue(
			{
				//这里是说用什么技术引擎，由于国内浏览器问题这里一般使用flash即可。其他的删除掉。
				//gears,flash,silverlight,browserplus,html5,html4
				runtimes : 'flash,html5,flash,silverlight,html4',
				//服务端上传路径
				url : '${ctx}/fileHandler/upLoaderMerge',
				//文件上传最大限制
				max_file_size : '5gb',
				// 上传的文件名是否唯一
				unique_names : true,
				//上传分块每块的大小，这个值小于服务器最大上传限制的值即可。（文件总大小/chunk_size = 分块数）
				//目前该参数在后台不知道怎么获得，暂时屏蔽
				//chunk_size: '2mb',
				//是否生成缩略图（仅对图片文件有效）
				resize : {width : "900", height : "470", quality : "90"},  
				//不允许队列中存在重复文件
				prevent_duplicates : true, 
				//这个数组是选择器，就是上传文件时限制的上传文件类型  
				filters : [{
					title : "图片",
					//extensions : "jpg,bmp,gif,png,ini,txt,doc,excel,zip,rar,docx,ppt,pdf"
					extensions : "*"
				} ],
				//plupload.flash.swf 的所在路径
				flash_swf_url : '${ctx}/js/plupload/plupload.flash.swf',
				//silverlight所在路径
				silverlight_xap_url : '${ctx}/js/plupload/plupload.silverlight.xap',
				init : {
					//文件队列变化时触发
					//QueueChanged : function(uploader, files) {},
					//文件上传成功时触发
					FileUploaded : function(uploader, file,	response) {
						if (response.response) {
							/* var a= "\'"+response.response+"\'";
							var b= response.response; */
							/* var c  = eval("(" + b+ ")");  */
							var rs = JSON.parse(response.response);
							if (rs.status) {
								if (fileids == "") {
									fileids = rs.fileIds;
								} else {
									fileids += "," + rs.fileIds;
								}
								$("#fileIds").val(fileids);
								var html = "<a style='font-style: italic;text-decoration: underline;color: #0E68EF;' onclick=\"downLoadFile("+"'"+"${sessionScope.image_logo}"+fileids+"'"+");\">app下载</a>"
								$("#down").html(html);
								
								files.push(file.name);
								
								file.fileId = rs.fileIds;
								fileList.push(file);
							} else {
								errors.push(file.name);
							}
						}
					},
					//队列中所有文件上传完时触发
					UploadComplete : function(uploader, fs) {
						var e = errors.length ? ",失败" + errors.length + "个(" + errors.join("、") + ")。" : "。";
						$("#res").text("上传完成！共" + fs.length + "个。成功" + files.length + e);
					},
					//用户选择文件时触发 (限制上传文件数量，需改进，暂时不考虑)
					FilesAdded: function (uploader, files) {	
		                var fileAmount = $("#fileAmount").val();
		                var amount = Number(fileAmount);
					    if (fileAmount != null && uploader.files.length >= amount) {
					    	 uploader.splice(amount, 999);
						}
					    noUploadFiles = uploader.files;
					    
					    /*  if (uploade == null) {
					    	uploade = uploader;
					    }  */
					    
					    if(type != null && type == "import"){
							uploade.settings.url = "${ctx}/importXls"
						}
			        },
			        //销毁plupload实例对象 
			        Destroy: function(uploader){
			        	uploader.destroy(); 
			        }
				}
			});
			
			//这一块主要是防止在上传未结束前表带提交
			$("form[id='formId']").submit(function(e)  {
				// 取得上传队列
				var uploader = $('#uploader').pluploadQueue();
				if (uploader.files.length > 0) {
					// When all files are uploaded submit form
					uploader.bind('StateChanged',function() {
						if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
							$('form')[0].submit();
						}
					});
					//开始上传 
					uploader.start();
				} else {
					$.jBox.tip('请先上传数据文件.');
				}
				return false;
			});
		//});
	}
	
</script>
<!-- 上传窗口begin -->
<div id="upload" style="display: none;">
	<!-- 盖住原窗体，愿意是形成模式窗体，但没达到目的，可删除 -->
	<div id="zzc"></div>
	<!-- 隐藏层，默认不显示，ID可任意命名 -->
	<div id="tcctcs">
		<!-- 这个还为弄清楚，但ID不能变化，一旦变化就达不到目的 -->
		<div id="jgsztcc" class="jgsztcc" style="height: 464px;width: 600px">
			<div class="tcc">
				<span class="tccgb" title="关闭">&times;</span>
				<!-- 关闭图标 -->
				<div class="tcctop">文件上传</div>
				<div class="tccmain">
					<div class="yqjsqta">
						<div id="uploader">
							<p>您的浏览器未安装 Flash, Silverlight, Gears, BrowserPlus 或者支持 HTML5...</p>
							<div id="res">&nbsp;</div>
						</div>
						<input class="" type="button" value="完成" onclick="fileUploadFinish()"/>
					</div>
				</div>
			</div>
		</div>		
	</div>
</div>
<!-- 上传窗口end -->